/*
 * @Author: zhengzhuang
 * @since: 2020-01-06 15:17:27
 * @lastTime: 2020-02-29 14:06:15
 * @LastAuthor: zhengzhuang
 * @FilePath: /C20Driver/lib/pages/index_page/index_carpool/index_carpool.dart
 * @message: 顺风车   IndexCarpool
 */

import 'dart:io';

import 'package:C20Driver/provider/position_information.dart';
import 'package:C20Driver/utils/permission_handler.dart';
import 'package:C20Driver/utils/utils.dart';
import 'package:amap_location_fluttify/amap_location_fluttify.dart';
import 'package:amap_map_fluttify/amap_map_fluttify.dart';
import 'package:amap_search_fluttify/amap_search_fluttify.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/event/event_bus.dart';
import 'package:C20Driver/model/get_free_ride_order_data.dart';
import 'package:C20Driver/model/user_realtime_location_model.dart';
import 'package:C20Driver/provider/order_information.dart';
import 'package:C20Driver/routers/navigator_util.dart';
import 'package:C20Driver/service/request.dart';
import 'package:provider/provider.dart';
import 'index_carpool_map.dart';
import 'windmill_order_progress.dart';

class IndexCarpool extends StatefulWidget {
  final amapControllerCallBack;
  IndexCarpool({this.amapControllerCallBack});
  @override
  _IndexCarpoolState createState() => _IndexCarpoolState();
}

class _IndexCarpoolState extends State<IndexCarpool>
    with
        SingleTickerProviderStateMixin,
        AutomaticKeepAliveClientMixin,
        WidgetsBindingObserver {
  @override
  bool get wantKeepAlive => true;

  double _bottomHeight = 0;
  bool showTimeNum = false;
  bool showPassDetail = false;
  Map _homeItineraryList = {}; // 顺风车列表
  GetFreeRideOrderData _dataInfo = GetFreeRideOrderData();
  AmapController _amapController;
  // LatLng(res.latLng.latitude, res.latLng.longitude)
  var markerList = [];
  List<Marker> _markers = [];
  @override
  void initState() {
    super.initState();
    Future.microtask(() {
      var homeViewModel = Provider.of<OrderInformation>(context, listen: false);
      homeViewModel.setCarpoolTime();
    });
    _getFreeRideOrderList();

    eventBus.on<OrderWindmillTravel>().listen((event) {
      print("OrderWindmillTravel");
      _getFreeRideOrderList();
    });
    eventBus.on<CancelCarpoolOrderMark>().listen((event) async {
      print("CancelCarpoolOrderMark");
      if (mounted) {
        setState(() {
          markerList = [];
          _amapController?.clear();
          showTimeNum = false;
        });
      }
      if (await PermissionHandlerX.position(context)) {
        /// 获取我的定位
        await AmapLocation.fetchLocation().then((res) {
          // 延时1s执行返回
          Future.delayed(Duration(milliseconds: 300), () async {
            /// 设置当前我的位置
            _amapController.setCenterCoordinate(
                LatLng(res.latLng.latitude, res.latLng.longitude));
            // 设置缩放级别
            await _amapController.setZoomLevel(15.0);
          });
        });
      }
    });
    WidgetsBinding.instance?.addObserver(this);
  }

  /// 查询是否有进行中的订单
  Future _getFreeRideOrderList() async {
    await Request.getFreeRideOrderList().then((value) async {
      Map _value = value;
      if (_value.length != 0) {
        getFreeRideOrderDataFun(_value);
      } else {
        if (mounted) {
            _homeItineraryList = {};

        }
      }
    });
  }

  /// 进行中的订单信息
  Future getFreeRideOrderDataFun(data) async {
    return await Request.getFreeRideOrderDataFun(data['id']).then((value) {
      Provider.of<OrderInformation>(context, listen: false).setCarpoolOrderInfo(
        orderId: value['id'],
        departureDate: value['departure_date'],
        depLongitude: value['dep_longitude'],
        depLatitude: value['dep_latitude'],
        depAre: value['dep_are'],
        destLongitude: value['dest_longitude'],
        destLatitude: value['dest_latitude'],
        destArea: value['dest_area'],
        state: value['state'],
        seatNum: value['seat_num'],
      );
      if (mounted) {
        setState(() {
          _homeItineraryList = data;
        });
      }

      _dataInfo = GetFreeRideOrderData.fromJson(value);
      // _dataInfo.orderId = data['id'];
    });
  }

  @override
  Widget build(BuildContext context) {
    print("buildbuildbuildbuildbuildbuildbuildbuildbuildbuild");
    return Container(
      color: Colors.transparent,
      child: Stack(
        children: <Widget>[
          Container(
            width: ScreenUtil().setWidth(750.0),
            height: double.infinity,
            child: AmapView(
              // 地图类型
              mapType: MapType.Standard,
              // 是否显示缩放控件
              showZoomControl: true,
              // 是否显示指南针控件
              showCompass: true,
              // 是否显示比例尺控件
              showScaleControl: true,
              // 是否使能缩放手势
              zoomGesturesEnabled: true,
              // 是否使能滚动手势
              scrollGesturesEnabled: true,
              // 是否使能旋转手势
              rotateGestureEnabled: true,
              // 是否使能倾斜手势
              tiltGestureEnabled: true,
              // 缩放级别
              zoomLevel: 17.0,
              centerCoordinate:
                  Provider.of<PositionInformation>(context, listen: false)
                      .driverLocation,
              onMapCreated: (controller) async {
                _amapController = controller;
                widget.amapControllerCallBack(controller);
                if (await PermissionHandlerX.position(context)) {
                  await AmapLocation.fetchLocation().then((res) {
                    print(LatLng(res.latLng.latitude, res.latLng.longitude));
                    var lat = {
                      'lat': double.parse(res.latLng.latitude.toString()),
                      'lng': double.parse(res.latLng.longitude.toString()),
                      'name': res.address,
                      'cityName': res.city,
                      'image': 'assets/icon/shunfeng_qi.png'
                    };
                    var latDataJson = UserRealtimeLocationModel.fromJson(lat);
                    Provider.of<OrderInformation>(context, listen: false)
                        .onCarpoolMap(latDataJson, context);

                    markerList.insert(0, lat);

                    /// 设置当前我的位置
                    _amapController.setCenterCoordinate(
                        LatLng(res.latLng.latitude, res.latLng.longitude));
                  });
                }
              },
              onMapMoveStart: (drag) async {},
              onMapMoveEnd: (drag) async {},
              onMarkerClicked: ((marker) async {
                String tit = await marker.title;
                if (tit == '0') {
                  _selectQidian();
                } else {
                  _selectZongdian();
                }
                return true;
              }),
              onMapClicked: (latLng) {
                return;
              },
            ),
          ),
          Positioned(
            top: ScreenUtil().setHeight(150.0),
            right: ScreenUtil().setHeight(20.0),
            child: MaterialButton(
              minWidth: ScreenUtil().setHeight(80.0),
              height: ScreenUtil().setHeight(80.0),
              color: Colors.white,
              shape: RoundedRectangleBorder(
                borderRadius:
                    BorderRadius.circular(ScreenUtil().setWidth(100.0)),
              ),
              child: Icon(Icons.my_location),
              onPressed: () async {
                if (await PermissionHandlerX.position(context)) {
                  /// 获取我的定位
                  await AmapLocation.fetchLocation().then((res) {
                    /// 设置当前我的位置
                    _amapController.setCenterCoordinate(
                        LatLng(res.latLng.latitude, res.latLng.longitude));
                    // 延时1s执行返回
                    Future.delayed(Duration(seconds: 1), () async {
                      // 设置缩放级别
                      await _amapController.setZoomLevel(15.0);
                    });
                  });
                }
              },
            ),
          ),
          Positioned(
            top: ScreenUtil().setWidth(45),
            left: ScreenUtil().setWidth(115),
            child: _homeItineraryList.length == 0
                ? Container()
                : Offstage(
                    offstage: _homeItineraryList.length == 0,
                    child: GestureDetector(
                      behavior: HitTestBehavior.translucent,
                      onTap: () {
                        print('您有一笔进行中的订单请及时查看～');
                        NavigatorUtil.jump(context,
                            '/carpoolFellowPassengers?id=${_homeItineraryList["id"]}');
                      },
                      child: Container(
                        width: ScreenUtil().setWidth(520),
                        padding: EdgeInsets.fromLTRB(
                          ScreenUtil().setWidth(32),
                          ScreenUtil().setWidth(20),
                          ScreenUtil().setWidth(32),
                          ScreenUtil().setWidth(20),
                        ),
                        height: ScreenUtil().setWidth(80),
                        decoration: BoxDecoration(
                          color: Color(0xffffffff),
                          borderRadius: BorderRadius.all(
                            Radius.circular(
                              ScreenUtil().setWidth(24),
                            ),
                          ),
                          boxShadow: <BoxShadow>[
                            BoxShadow(
                              color: Color(0xff325B98),
                              blurRadius: ScreenUtil().setSp(5.0),
                            )
                          ],
                        ),
                        child: Row(
                          children: [
                            Text(
                              '您有一笔进行中的订单请及时查看～',
                              style: TextStyle(
                                  color: Color(0xff333333),
                                  fontSize: ScreenUtil().setWidth(26),
                                  fontWeight: FontWeight.w400),
                            ),
                            Icon(
                              Icons.chevron_right,
                              color: Color(0xff999999),
                              size: ScreenUtil().setWidth(30),
                            ),
                          ],
                        ),
                      ),
                    ),
                  ),
          ),
          Positioned(
            left: 0,
            bottom: ScreenUtil().setWidth(10.0),
            width: ScreenUtil().setWidth(750.0),
            child: Stack(
              children: [
                Offstage(offstage: showTimeNum, child: _releaseItinerary()),
                Offstage(
                  offstage: !showTimeNum,
                  child: _selectTimeAndNum(),
                ),
              ],
            ),
          ),
        ],
      ),
    );
  }

  ///选择座位和时间
  Widget _selectTimeAndNum() {
    return Container(
      padding: EdgeInsets.fromLTRB(
          ScreenUtil().setWidth(32),
          ScreenUtil().setWidth(40),
          ScreenUtil().setWidth(32),
          ScreenUtil().setWidth(40)),
      width: ScreenUtil().setWidth(750.0),
      decoration: BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.circular(ScreenUtil().setSp(32.0)),
        boxShadow: <BoxShadow>[
          BoxShadow(
            color: Colors.black12,
            blurRadius: ScreenUtil().setSp(12.0),
          ),
        ],
      ),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Consumer<OrderInformation>(
            builder: (ctx, state, child) {
              return _getTimeNumView(
                  '出行时间',
                  state.departureTime.length > 0
                      ? '${state.departureTime}'
                      : '选择出行时间',
                  0,
                  state.departureTime.length > 0 ? true : false);
            },
          ),
          SizedBox(
            height: ScreenUtil().setWidth(36),
          ),
          Consumer<OrderInformation>(
            builder: (ctx, state, child) {
              return _getTimeNumView(
                  '座位数量',
                  state.seatNum.length > 0 ? '${state.seatNum}' : '选择座位数量',
                  1,
                  state.seatNum.length > 0 ? true : false);
            },
          ),
          SizedBox(
            height: ScreenUtil().setWidth(36),
          ),
          Container(
            width: ScreenUtil().setWidth(650.0),
            height: ScreenUtil().setWidth(100.0),
            decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: [Color(0xff3FB956), Color(0xff65CA00)],
                ),
                borderRadius: BorderRadius.all(
                    Radius.circular(ScreenUtil().setWidth(50)))),
            child: MaterialButton(
              textColor: Colors.white,
              child: Text(
                '发布行程',
                style: TextStyle(
                    fontSize: ScreenUtil().setSp(32),
                    fontWeight: FontWeight.w500),
              ),
              onPressed: () {
                Request.sendReleaseSchedule(context);
              },
            ),
          ),
        ],
      ),
    );
  }

  Widget _getTimeNumView(String left, String right, int type, bool isSelect) {
    final provider =
        Provider.of<OrderInformation>(context, listen: false);
    return Container(
      width: double.infinity,
      height: ScreenUtil().setWidth(128),
      padding: EdgeInsets.all(ScreenUtil().setWidth(32)),
      decoration: BoxDecoration(
        color: Color(0xffF6F8FC),
        borderRadius: BorderRadius.all(
          Radius.circular(
            ScreenUtil().setWidth(15),
          ),
        ),
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Text(
            left,
            style: TextStyle(
              color: Color(0xff333333),
              fontSize: ScreenUtil().setSp(30),
            ),
          ),
          GestureDetector(
            behavior: HitTestBehavior.translucent,
            child: Container(
              alignment: Alignment.centerRight,
              child: Row(
                mainAxisSize: MainAxisSize.min,
                children: [
                  Text(
                    right,
                    style: TextStyle(
                      fontSize: ScreenUtil().setSp(30.0),
                      color: isSelect ? Color(0xff333333) : Color(0xffB5B5B5),
                    ),
                  ),
                  Icon(
                    Icons.chevron_right,
                    color: isSelect ? Color(0xff333333) : Color(0xffB5B5B5),
                    size: ScreenUtil().setWidth(40),
                  ),
                ],
              ),
            ),
            onTap: () {
              if (type == 0) {
                //0时间 1座位
                provider.chooseDepartureTime(context);
              } else {
                provider.modifiedSeatNumber(context);
              }
            },
          ),
        ],
      ),
    );
  }

  /// 选择地址View
  Widget _releaseItinerary() {
    return Container(
      width: ScreenUtil().setWidth(750.0),
      decoration: BoxDecoration(
          color: Colors.white,
          borderRadius: BorderRadius.circular(ScreenUtil().setSp(32.0)),
          boxShadow: <BoxShadow>[
            BoxShadow(
              color: Colors.black12,
              blurRadius: ScreenUtil().setSp(12.0),
            ),
          ]),
      child: Column(
        children: <Widget>[
          SizedBox(height: ScreenUtil().setWidth(15.0)),
          Row(
            mainAxisAlignment: MainAxisAlignment.start,
            children: [
              Padding(
                padding: EdgeInsets.only(
                  left: ScreenUtil().setWidth(40),
                  top: ScreenUtil().setWidth(32),
                ),
                child: Text(
                  '发布行程',
                  textAlign: TextAlign.left,
                  style: TextStyle(
                    fontSize: ScreenUtil().setSp(32),
                    fontWeight: FontWeight.w500,
                    color: Color(0xff333333),
                  ),
                ),
              ),
            ],
          ),
          GestureDetector(
            behavior: HitTestBehavior.translucent,
            child: Container(
              margin: EdgeInsets.only(
                left: ScreenUtil().setWidth(32.0),
                right: ScreenUtil().setWidth(32.0),
              ),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.spaceBetween,
                children: <Widget>[
                  Container(
                    margin: EdgeInsets.only(
                      left: ScreenUtil().setWidth(30),
                      right: ScreenUtil().setWidth(30),
                    ),
                    width: ScreenUtil().setWidth(15.0),
                    height: ScreenUtil().setWidth(15.0),
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      color: Color(0xff00BA8F),
                    ),
                  ),
                  Expanded(
                    child: Container(
                      alignment: Alignment.centerLeft,
                      width: ScreenUtil().setWidth(630.0),
                      padding: EdgeInsets.only(
                        top: ScreenUtil().setWidth(35.0),
                        bottom: ScreenUtil().setWidth(35.0),
                      ),
                      child: Consumer<OrderInformation>(
                        builder: (ctx, state, child) {
                          return Text(
                            '${state.windmillStartingPoint}',
                            style: TextStyle(
                              fontSize: ScreenUtil().setSp(34.0),
                              color: state.windmillStartingPoint == '请输入起点名称'
                                  ? Colors.black26
                                  : Color(0xff3FB956),
                            ),
                          );
                        },
                      ),
                    ),
                  ),
                  Padding(
                    padding: EdgeInsets.only(right: ScreenUtil().setWidth(10)),
                    child: Icon(
                      Icons.chevron_right,
                      color: Color(0xff999999),
                      size: ScreenUtil().setWidth(40),
                    ),
                  ),
                ],
              ),
            ),
            onTap: () {
              _selectQidian();
            },
          ),
          GestureDetector(
            behavior: HitTestBehavior.translucent,
            child: Container(
              margin: EdgeInsets.only(
                left: ScreenUtil().setWidth(32.0),
                right: ScreenUtil().setWidth(32.0),
              ),
              decoration: BoxDecoration(
                color: Color(0xffF6F8FC),
                borderRadius: BorderRadius.all(
                  Radius.circular(
                    ScreenUtil().setWidth(32),
                  ),
                ),
              ),
              child: Row(
                children: <Widget>[
                  Container(
                    width: ScreenUtil().setWidth(15.0),
                    height: ScreenUtil().setWidth(15.0),
                    margin: EdgeInsets.only(
                      left: ScreenUtil().setWidth(32),
                      right: ScreenUtil().setWidth(32),
                    ),
                    decoration: BoxDecoration(
                      shape: BoxShape.circle,
                      color: Color.fromARGB(255, 255, 102, 0),
                    ),
                  ),
                  Container(
                      // width: ScreenUtil().setWidth(630.0),
                      padding: EdgeInsets.only(
                        top: ScreenUtil().setWidth(35.0),
                        bottom: ScreenUtil().setWidth(35.0),
                      ),
                      child: Consumer<OrderInformation>(
                          builder: (ctx, state, child) {
                        return Text(
                          '${state.endOfWindmill}',
                          style: TextStyle(
                            fontSize: ScreenUtil().setSp(36.0),
                            fontWeight: FontWeight.w500,
                            color: Color(0xff333333),
                          ),
                        );
                      })),
                ],
              ),
            ),
            onTap: () async {
              _selectZongdian();
            },
          ),
          SizedBox(height: ScreenUtil().setWidth(20.0)),
          // MaterialButton(
          //   child: Text('发布行程',
          //       style: TextStyle(
          //           fontSize: ScreenUtil().setSp(36.0), color: Colors.white)),
          //   color: Color.fromARGB(255, 255, 153, 0),
          //   minWidth: ScreenUtil().setWidth(600.0),
          //   height: ScreenUtil().setWidth(88.0),
          //   onPressed: () => Request.sendReleaseSchedule(context),
          // ),
          SizedBox(height: ScreenUtil().setWidth(30.0)),
        ],
      ),
    );
  }

  //起点选择
  _selectQidian() {
    final provider =
        Provider.of<OrderInformation>(context, listen: false);
    NavigatorUtil.jump(context, '/locationSearchPage').then((res) {
      if (res == null) return;
      UserRealtimeLocationModel data = res;
      eventBus.fire(new SetMapLocation(LatLng(data.lat, data.lng)));
      provider.onCarpoolMap(res, context);
      if (markerList.length > 0) {
        markerList.removeAt(0);
      }
      markerList.insert(0, {
        'lat': res.lat,
        'lng': res.lng,
        'name': res.name,
        'image': 'assets/icon/shunfeng_qi.png'
      });
      if (markerList.length > 1) {
        _amapController?.addPolyline(PolylineOption(
          latLngList: [
            LatLng(markerList[0]['lat'], markerList[0]['lng']),
            LatLng(markerList[1]['lat'], markerList[1]['lng']),
          ],
          width: 10,
          strokeColor: Colors.green,
        ));

        if (mounted) {
          /// 设置两点图片
            _addMarkerView();
            _amapController?.clear();

        }

        /// 将指定的经纬度列表(包括但不限于marker, polyline, polygon等)调整至同一屏幕中显示
        List<LatLng> arr = [
          LatLng(markerList[0]['lat'], markerList[0]['lng']),
          LatLng(markerList[1]['lat'], markerList[1]['lng']),
        ];
        Future.delayed(Duration(milliseconds: 500), () {
          if (mounted) {
            setState(() {
              _amapController?.zoomToSpan(arr,
                  padding: EdgeInsets.all(ScreenUtil().setWidth(15.0)));
              _amapController?.addPolyline(PolylineOption(
                latLngList: [
                  LatLng(markerList[0]['lat'], markerList[0]['lng']),
                  LatLng(markerList[1]['lat'], markerList[1]['lng']),
                ],
                width: 10,
                strokeColor: Colors.green,
              ));
              _addMarkerView();
            });
          }
        });
      }
    });
  }

  //重点选择
  _selectZongdian() {
    final provider =
        Provider.of<OrderInformation>(context, listen: false);
    NavigatorUtil.jump(context, '/locationSearchPage').then((res) {
      if (res != null) {
        if (mounted) {
          setState(() {
            showTimeNum = true;
          });
        }

        provider.setCarpoolEndInfo(res);
        if (markerList.length > 1) {
          markerList.removeAt(1);
        }
        markerList.insert(1, {
          'lat': res.lat,
          'lng': res.lng,
          'name': res.name,
          'image': 'assets/icon/shunfeng_zhong.png'
        });
        print('iiiiiiiii====' + markerList.toString());

        /// 两点直线距离
        if (mounted) {
          /// 设置两点图片
            _addMarkerView();
            _amapController?.clear();

        }

        /// 将指定的经纬度列表(包括但不限于marker, polyline, polygon等)调整至同一屏幕中显示
        List<LatLng> arr = [
          LatLng(markerList[0]['lat'], markerList[0]['lng']),
          LatLng(markerList[1]['lat'], markerList[1]['lng']),
        ];

        Future.delayed(Duration(milliseconds: 500), () {
          if (mounted) {
            setState(() {
              _amapController?.zoomToSpan(arr,
                  padding: EdgeInsets.all(ScreenUtil().setWidth(0.0)));
              _amapController?.addPolyline(PolylineOption(
                latLngList: [
                  LatLng(markerList[0]['lat'], markerList[0]['lng']),
                  LatLng(markerList[1]['lat'], markerList[1]['lng']),
                ],
                width: 10,
                strokeColor: Colors.green,
              ));
              _addMarkerView();
            });
          }
        });
      }
    });
  }

  _addMarkerView() {
    double width = Utils.getDeviceMediaInfoWidth(context);
    print("widthwidthwidthwidthwidthwidthwidthwidth=====" + width.toString());
    double maxW = 200.0;
    int fontSize = 10;
    double imageW = 40;
    double imageH = 50;
    if (width > 1200) {
      maxW = 120.0;
      fontSize = 7;
      imageW = 20;
      imageH = 30;
    } else if (width > 1100) {
      maxW = 140.0;
      fontSize = 8;
      imageW = 30;
      imageH = 40;
    }
    _amapController?.addMarkers(
      [
        MarkerOption(
          latLng: LatLng(markerList[0]['lat'], markerList[0]['lng']),
          title: '0',
          snippet: '22',
          widget: Container(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                GestureDetector(
                  behavior: HitTestBehavior.translucent,
                  onTap: () {
                    _selectQidian();
                  },
                  child: Container(
                    padding: EdgeInsets.fromLTRB(
                        ScreenUtil().setWidth(10),
                        ScreenUtil().setWidth(8),
                        ScreenUtil().setWidth(8),
                        ScreenUtil().setWidth(8)),
                    // width: ScreenUtil().setWidth(280),
                    margin: EdgeInsets.only(
                        right: ScreenUtil().setWidth(3),
                        bottom: ScreenUtil().setWidth(3)),
                    decoration: BoxDecoration(
                      color: Color(0xffffffff),
                      borderRadius: BorderRadius.all(
                        Radius.circular(ScreenUtil().setWidth(15)),
                      ),
                      boxShadow: <BoxShadow>[
                        //设置阴影
                        new BoxShadow(
                          color: Color.fromARGB(25, 0, 0, 0), //阴影颜色
                          blurRadius: 1.0, //阴影大小
                          offset: Offset(1, 1),
                        ),
                      ],
                    ),
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Container(
                          constraints: BoxConstraints(
                              maxWidth: Platform.isIOS
                                  ? ScreenUtil().setWidth(maxW)
                                  : ScreenUtil().setWidth(320)),
                          child: Text(
                            markerList[0]['name'],
                            style: TextStyle(
                                color: Color(0xff333333),
                                fontSize: Platform.isIOS
                                    ? ScreenUtil().setSp(fontSize)
                                    : 14,
                                fontWeight: FontWeight.w500),
                          ),
                        ),
                        SizedBox(
                          width: ScreenUtil().setWidth(5),
                        ),
                        Icon(
                          Icons.chevron_right,
                          color: Color(0xff999999),
                          size: ScreenUtil().setWidth(15),
                        )
                      ],
                    ),
                  ),
                ),
                Image.asset(
                  markerList[0]['image'],
                  width: Platform.isIOS
                      ? ScreenUtil().setWidth(imageW)
                      : ScreenUtil().setWidth(40),
                  height: Platform.isIOS
                      ? ScreenUtil().setWidth(imageH)
                      : ScreenUtil().setWidth(50),
                  fit: BoxFit.fitWidth,
                ),
              ],
            ),
          ),
          anchorV: 0.9,
          anchorU: 0.5,
          draggable: false,
          infoWindowEnabled: false,
        ),
        MarkerOption(
          latLng: LatLng(markerList[1]['lat'], markerList[1]['lng']),
          title: '1',
          snippet: '33',
          widget: Container(
            child: Column(
              mainAxisSize: MainAxisSize.min,
              children: [
                GestureDetector(
                  behavior: HitTestBehavior.translucent,
                  onTap: () {
                    _selectZongdian();
                  },
                  child: Container(
                    padding: EdgeInsets.fromLTRB(
                        ScreenUtil().setWidth(10),
                        ScreenUtil().setWidth(8),
                        ScreenUtil().setWidth(8),
                        ScreenUtil().setWidth(8)),
                    // width: ScreenUtil().setWidth(280),
                    margin: EdgeInsets.only(
                        right: ScreenUtil().setWidth(3),
                        bottom: ScreenUtil().setWidth(3)),
                    decoration: BoxDecoration(
                      color: Color(0xffffffff),
                      borderRadius: BorderRadius.all(
                        Radius.circular(ScreenUtil().setWidth(15)),
                      ),
                      boxShadow: <BoxShadow>[
                        //设置阴影
                        new BoxShadow(
                          color: Color.fromARGB(25, 0, 0, 0), //阴影颜色
                          blurRadius: 1.0, //阴影大小
                          offset: Offset(1, 1),
                        ),
                      ],
                    ),
                    child: Row(
                      mainAxisSize: MainAxisSize.min,
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Container(
                          constraints: BoxConstraints(
                              maxWidth: Platform.isIOS
                                  ? ScreenUtil().setWidth(maxW)
                                  : ScreenUtil().setWidth(320)),
                          child: Text(
                            markerList[1]['name'],
                            style: TextStyle(
                                color: Color(0xff333333),
                                fontSize: Platform.isIOS
                                    ? ScreenUtil().setSp(fontSize)
                                    : 14,
                                fontWeight: FontWeight.w500),
                          ),
                        ),
                        SizedBox(
                          width: ScreenUtil().setWidth(5),
                        ),
                        Icon(
                          Icons.chevron_right,
                          color: Color(0xff999999),
                          size: ScreenUtil().setWidth(15),
                        )
                      ],
                    ),
                  ),
                ),
                Image.asset(
                  markerList[1]['image'],
                  width: Platform.isIOS
                      ? ScreenUtil().setWidth(imageW)
                      : ScreenUtil().setWidth(40),
                  height: Platform.isIOS
                      ? ScreenUtil().setWidth(imageH)
                      : ScreenUtil().setWidth(50),
                  fit: BoxFit.fitWidth,
                ),
              ],
            ),
          ),
          anchorV: 0.9,
          anchorU: 0.5,
          draggable: false,
          infoWindowEnabled: false,
        ),
      ],
    );
  }

  // @override
  // void didChangeAppLifecycleState(AppLifecycleState state) {
  //   super.didChangeAppLifecycleState(state);
  //   switch (state) {
  //     //进入应用时候不会触发该状态 应用程序处于可见状态，并且可以响应用户的输入事件。它相当于 Android 中Activity的onResume
  //     case AppLifecycleState.resumed:
  //       print("应用进入前台======");
  //       setState(() {});
  //       break;
  //     //应用状态处于闲置状态，并且没有用户的输入事件，
  //     // 注意：这个状态切换到 前后台 会触发，所以流程应该是先冻结窗口，然后停止UI
  //     case AppLifecycleState.inactive:
  //       print("应用处于闲置状态，这种状态的应用应该假设他们可能在任何时候暂停 切换到后台会触发======");
  //       break;
  //     //当前页面即将退出
  //     case AppLifecycleState.detached:
  //       print("当前页面即将退出======");
  //       break;
  //     // 应用程序处于不可见状态
  //     case AppLifecycleState.paused:
  //       print("应用处于不可见状态 后台======");
  //       break;
  //   }
  // }

  @override
  void dispose() {
    WidgetsBinding.instance?.removeObserver(this);
    _amapController.dispose();
    // _amapController = null;
    super.dispose();
  }
}
